package com.duanjw.springcloud.seata.consumer.service.impl;

import com.duanjw.springcloud.seata.consumer.feign.UserService;
import com.duanjw.springcloud.seata.consumer.mapper.OrderMapper;
import com.duanjw.springcloud.seata.consumer.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户 ServiceImpl
 *
 * @author duanjw
 */
@Service
public class OrderServiceImpl implements OrderService {
    private final OrderMapper orderMapper;
    private final UserService userService;

    public OrderServiceImpl(OrderMapper orderMapper, UserService userService) {
        this.orderMapper = orderMapper;
        this.userService = userService;
    }

    /**
     * 根据id删除订单
     * 开启全局事务
     *
     * @param id
     * @return
     */
    @Override
//    @Transactional(rollbackFor = Exception.class)
    @GlobalTransactional(rollbackFor = Exception.class)
    public int deleteById(Integer id) {
        userService.deleteById(id);
        orderMapper.deleteById(id);
        throw new RuntimeException();
    }
}
